#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,v,anso,anst,ai[100001],di[100001],vi[100001],p[100001],dmax;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d %d %d %d",&n,&m,&L,&v);
        for(int i=0;i<n;i++){
            scanf("%d %d %d",&di[i],&vi[i],&ai[i]);
            if(ai[i]==0){
                continue;
            }else if(ai[i]>0){
                if(vi[i]>v){
                    continue;
                }
                di[i]=(v*v-vi[i]*vi[i])/(ai[i]*2)+di[i]+1;
                vi[i]=v+1;
            }
        }for(int i=0;i<m;i++){
            scanf("%d",&p[i]);
        }
        for(int i=0;i<n;i++){
            if(vi[i]>v&&di[i]<=p[m-1]){
                anso++;
                dmax=max(dmax,di[i]);
            }
        }for(int i=0;i<m;i++){
            if(p[i]>=dmax&&dmax!=0){
                anst=1;
            }
        }

        printf("%d %d\n",anso,m-anst);
        dmax=0;
        anso=0;
        anst=0;
    }
    return 0;
}
